package com.ruoyi.goodsInfoNew.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.goodsInfoNew.domain.GoodsNew;
import com.ruoyi.goodsInfoNew.service.IGoodsNewService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商品主表Controller
 * 
 * @author ruoyi
 * @date 2025-05-22
 */
@RestController
@RequestMapping("/goodsInfoNew/goods_new")
public class GoodsNewController extends BaseController
{
    @Autowired
    private IGoodsNewService goodsNewService;

    /**
     * 查询商品主表列表
     */
    @PreAuthorize("@ss.hasPermi('goodsInfoNew:goods_new:list')")
    @GetMapping("/list")
    public TableDataInfo list(GoodsNew goodsNew)
    {
        startPage();
        List<GoodsNew> list = goodsNewService.selectGoodsNewList(goodsNew);
        return getDataTable(list);
    }

    /**
     * 导出商品主表列表
     */
    @PreAuthorize("@ss.hasPermi('goodsInfoNew:goods_new:export')")
    @Log(title = "商品主表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GoodsNew goodsNew)
    {
        List<GoodsNew> list = goodsNewService.selectGoodsNewList(goodsNew);
        ExcelUtil<GoodsNew> util = new ExcelUtil<GoodsNew>(GoodsNew.class);
        util.exportExcel(response, list, "商品主表数据");
    }

    /**
     * 获取商品主表详细信息
     */
    @PreAuthorize("@ss.hasPermi('goodsInfoNew:goods_new:query')")
    @GetMapping(value = "/{goodsId}")
    public AjaxResult getInfo(@PathVariable("goodsId") Long goodsId)
    {
        return success(goodsNewService.selectGoodsNewByGoodsId(goodsId));
    }

    /**
     * 新增商品主表
     */
    @PreAuthorize("@ss.hasPermi('goodsInfoNew:goods_new:add')")
    @Log(title = "商品主表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GoodsNew goodsNew)
    {
        return toAjax(goodsNewService.insertGoodsNew(goodsNew));
    }

    /**
     * 修改商品主表
     */
    @PreAuthorize("@ss.hasPermi('goodsInfoNew:goods_new:edit')")
    @Log(title = "商品主表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GoodsNew goodsNew)
    {
        return toAjax(goodsNewService.updateGoodsNew(goodsNew));
    }

    /**
     * 删除商品主表
     */
    @PreAuthorize("@ss.hasPermi('goodsInfoNew:goods_new:remove')")
    @Log(title = "商品主表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{goodsIds}")
    public AjaxResult remove(@PathVariable Long[] goodsIds)
    {
        return toAjax(goodsNewService.deleteGoodsNewByGoodsIds(goodsIds));
    }
}
